/**
    @author: dt
    @date: 2025-06-23
    @description: 等待任务节点
*/
using UnityEngine;

namespace DLib.BehaviorTree.Tasks
{
    /// <summary>
    /// 等待任务节点
    /// 用于在行为树中实现时间延迟
    /// 等待指定时间后返回成功
    /// </summary>
    public class WaitTask : TaskNode
    {
        /// <summary>等待时间（秒）</summary>
        private float waitTime;
        
        /// <summary>任务开始时间</summary>
        private float startTime;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="waitTime">等待时间（秒）</param>
        public WaitTask(float waitTime)
        {
            this.waitTime = waitTime;
        }

        /// <summary>
        /// 任务开始时的初始化
        /// 记录开始时间
        /// </summary>
        protected override void OnStart()
        {
            startTime = Time.time;
        }

        /// <summary>
        /// 任务更新逻辑
        /// 检查是否达到等待时间，如果达到则返回成功
        /// </summary>
        /// <returns>任务执行状态</returns>
        protected override NodeState OnUpdate()
        {
            // 检查是否达到等待时间
            if (Time.time - startTime >= waitTime)
            {
                return NodeState.Success;
            }
            
            // 还未达到等待时间，继续等待
            return NodeState.Running;
        }
    }
} 